﻿namespace System;

public static class TypeExtension
{
    public static object? CreateInstance(this Type type)
    {
        return Activator.CreateInstance(type);
    }

    #region 
    private static ConcurrentDictionary<string, Type> TypeDict = new ConcurrentDictionary<string, Type>();

    public static Type LoadType(string assemblyName, string typeName)
    {
        if (TypeDict.TryGetValue(typeName, out Type type))
            return type;

        var assembly = Assembly.Load(assemblyName);
        type = assembly?.GetType(typeName);

        if (type != null) TypeDict.TryAdd(typeName, type);
        return type;
    }

    #endregion
}